




/*
'===============================================================================
'  HNG.Portal.BL.TblDanhMucPhotoManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblDanhMucPhotoManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_LangId="LangId";
				
				public const String Field_TenDanhMucPhoto="TenDanhMucPhoto";
				
				public const String Field_Link="Link";
				
				public const String Field_Icon="Icon";
				
				public const String Field_TrangThai="TrangThai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblDanhMucPhotoManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_LangId,typeof(int));
			
						
			
			dt.Columns.Add(Field_TenDanhMucPhoto,typeof(string));
			
						
			
			dt.Columns.Add(Field_Link,typeof(string));
			
						
			
			dt.Columns.Add(Field_Icon,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblDanhMucPhotoEntity Convert_Entity(TblDanhMucPhotoEntity _TblDanhMucPhotoEntity,TblDanhMucPhotoEntity _TblDanhMucPhotoEntity_XML)
		{	
			
				
			_TblDanhMucPhotoEntity.Id= _TblDanhMucPhotoEntity_XML.Id;
				
			_TblDanhMucPhotoEntity.LangId= _TblDanhMucPhotoEntity_XML.LangId;
				
			_TblDanhMucPhotoEntity.TenDanhMucPhoto= _TblDanhMucPhotoEntity_XML.TenDanhMucPhoto;
				
			_TblDanhMucPhotoEntity.Link= _TblDanhMucPhotoEntity_XML.Link;
				
			_TblDanhMucPhotoEntity.Icon= _TblDanhMucPhotoEntity_XML.Icon;
				
			_TblDanhMucPhotoEntity.TrangThai= _TblDanhMucPhotoEntity_XML.TrangThai;
				
			
			return _TblDanhMucPhotoEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblDanhMucPhotoEntity Insert(TblDanhMucPhotoEntity TblDanhMucPhotoEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblDanhMucPhotoEntity, true);
			}
			return TblDanhMucPhotoEntity;
		}

		
		public TblDanhMucPhotoEntity Insert(int Id, int LangId, string TenDanhMucPhoto, string Link, string Icon, bool TrangThai)
		{
			TblDanhMucPhotoEntity _TblDanhMucPhotoEntity = new TblDanhMucPhotoEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblDanhMucPhotoEntity.Id = Id;
				_TblDanhMucPhotoEntity.LangId = LangId;
				_TblDanhMucPhotoEntity.TenDanhMucPhoto = TenDanhMucPhoto;
				_TblDanhMucPhotoEntity.Link = Link;
				_TblDanhMucPhotoEntity.Icon = Icon;
				_TblDanhMucPhotoEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblDanhMucPhotoEntity, true);
			}
			return _TblDanhMucPhotoEntity;
		}

		public TblDanhMucPhotoEntity Insert(int LangId, string TenDanhMucPhoto, string Link, string Icon, bool TrangThai)
		{
			TblDanhMucPhotoEntity _TblDanhMucPhotoEntity = new TblDanhMucPhotoEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblDanhMucPhotoEntity.LangId = LangId;
				_TblDanhMucPhotoEntity.TenDanhMucPhoto = TenDanhMucPhoto;
				_TblDanhMucPhotoEntity.Link = Link;
				_TblDanhMucPhotoEntity.Icon = Icon;
				_TblDanhMucPhotoEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblDanhMucPhotoEntity, true);
			}
			return _TblDanhMucPhotoEntity;
		}

		public bool Update(TblDanhMucPhotoEntity _TblDanhMucPhotoEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblDanhMucPhotoFields.Id == _TblDanhMucPhotoEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblDanhMucPhotoEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblDanhMucPhotoEntity _TblDanhMucPhotoEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblDanhMucPhotoEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int LangId, string TenDanhMucPhoto, string Link, string Icon, bool TrangThai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDanhMucPhotoEntity _TblDanhMucPhotoEntity = new TblDanhMucPhotoEntity(Id);
				if (adapter.FetchEntity(_TblDanhMucPhotoEntity))
				{
				
					_TblDanhMucPhotoEntity.LangId = LangId;
					_TblDanhMucPhotoEntity.TenDanhMucPhoto = TenDanhMucPhoto;
					_TblDanhMucPhotoEntity.Link = Link;
					_TblDanhMucPhotoEntity.Icon = Icon;
					_TblDanhMucPhotoEntity.TrangThai = TrangThai;
					adapter.SaveEntity(_TblDanhMucPhotoEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDanhMucPhotoEntity _TblDanhMucPhotoEntity = new TblDanhMucPhotoEntity(Id);
				if (adapter.FetchEntity(_TblDanhMucPhotoEntity))
				{
					adapter.DeleteEntity(_TblDanhMucPhotoEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblDanhMucPhotoEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDanhMucPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLangId(int LangId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDanhMucPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTenDanhMucPhoto(string TenDanhMucPhoto)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.TenDanhMucPhoto == TenDanhMucPhoto);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDanhMucPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLink(string Link)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDanhMucPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByIcon(string Icon)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Icon == Icon);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDanhMucPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDanhMucPhotoEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblDanhMucPhotoEntity SelectOne(int Id)
		{
			TblDanhMucPhotoEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDanhMucPhotoEntity _TblDanhMucPhotoEntity = new TblDanhMucPhotoEntity(Id);
				if (adapter.FetchEntity(_TblDanhMucPhotoEntity))
				{
					toReturn = _TblDanhMucPhotoEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection( new TblDanhMucPhotoEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDanhMucPhotoCollection, null, 0, null);
			}
			return _TblDanhMucPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDanhMucPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDanhMucPhotoCollection, filter, 0, null);
			}
			return _TblDanhMucPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDanhMucPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLangId(int LangId)
		{
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDanhMucPhotoCollection, filter, 0, null);
			}
			return _TblDanhMucPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLangIdRDT(int LangId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDanhMucPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTenDanhMucPhoto(string TenDanhMucPhoto)
		{
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.TenDanhMucPhoto == TenDanhMucPhoto);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDanhMucPhotoCollection, filter, 0, null);
			}
			return _TblDanhMucPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTenDanhMucPhotoRDT(string TenDanhMucPhoto)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.TenDanhMucPhoto == TenDanhMucPhoto);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDanhMucPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLink(string Link)
		{
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDanhMucPhotoCollection, filter, 0, null);
			}
			return _TblDanhMucPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLinkRDT(string Link)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDanhMucPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByIcon(string Icon)
		{
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Icon == Icon);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDanhMucPhotoCollection, filter, 0, null);
			}
			return _TblDanhMucPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIconRDT(string Icon)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.Icon == Icon);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDanhMucPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDanhMucPhotoCollection, filter, 0, null);
			}
			return _TblDanhMucPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDanhMucPhotoCollection = new EntityCollection(new TblDanhMucPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDanhMucPhotoFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDanhMucPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
